﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text.RegularExpressions;

public partial class Controls_Template_ThongTinChung : System.Web.UI.UserControl
{
    int SIZE_PART = 8;
    class_database db;
    class_string cs;

    protected void Page_Load(object sender, EventArgs e)
    {
        string idMau = Convert.ToString(Session["idMau"]);
        for (int i = 1; i <= SIZE_PART; i++)
        {
            LoadData(i, idMau);
        }
        if (!IsPostBack)
        {
            CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
            _FileBrowser.BasePath = "ckfinder";
            _FileBrowser.SetupCKEditor(ckEditorTongQuan);
        }
        SetDisplayEditDeleteDrop();
        SetTitle(idMau);
    }

    protected void drpPermission_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        db = new class_database();
        string value = drpPermission.SelectedValue.ToString();
        string idMau = Session["idMau"].ToString();
        string[] _param = {"permission"};
        string[] _value = {value};
        string _where = "idmau = " + idMau + " AND idloaibai = 1";
        db.UpdateRecord("tbl_baiphantich", _param, _value, _where);
    }

    protected void SetDisplayEditDeleteDrop()
    {
        string sessionUserType = Session["user_type"].ToString();
        string sessionUser = Session["username"].ToString();
        string idMau = Session["idMau"].ToString();
        string nguoiPhanTich = GetNguoiPhanTich(idMau);
        if (sessionUserType == "0")
        {
            drpPermission.Attributes.Add("style", "display: inline-block");
            string sqlGetPermission = "SELECT permission FROM tbl_baiphantich WHERE idloaibai = 1 AND idmau = " + idMau;
            db = new class_database();
            DataTable dt = db.GetDataTable(sqlGetPermission);
            if (dt != null && dt.Rows.Count > 0)
            {
                drpPermission.SelectedValue = dt.Rows[0]["permission"].ToString();
            }
        }
        if (sessionUserType == "0" || nguoiPhanTich.ToLower() == sessionUser)
        {
            btnEditThongTinChung.Attributes.Add("style", "display: inline-block");
            btnDeleteThongTinChung.Attributes.Add("style", "display: inline-block");
        }
    }

    protected string GetNguoiPhanTich(string idMau)
    {
        string sql = "SELECT tbl_user.name FROM tbl_mau, tbl_user WHERE tbl_mau.nguoiphantich = tbl_user.id AND tbl_mau.id = " + idMau;
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        string nameNguoiPhanTich = "";
        if (dt != null && dt.Rows.Count > 0)
        {
            nameNguoiPhanTich = dt.Rows[0]["name"].ToString();
        }
        return nameNguoiPhanTich;
    }

    protected void SetTitle(string idMau)
    {
        string sql = "SELECT tbl_mau.tenhamdiet, tbl_mau.date, tbl_user.name FROM tbl_mau, tbl_user WHERE tbl_mau.nguoiphantich = tbl_user.id AND tbl_mau.id = " + idMau;
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        if (dt != null && dt.Rows.Count > 0)
        {
            lblNguoiPhanTich.Text = "Người phân tích: " + dt.Rows[0]["name"].ToString();
            lblNgay.Text = "Ngày: " + dt.Rows[0]["date"].ToString();
            lblTenHamDiet.Text = "Tên hàm diệt: " + dt.Rows[0]["tenhamdiet"].ToString();
        }
    }

    private void LoadData(int typePart, string idMau)
    {
        string sql = "SELECT id, noidung, thongtin FROM tbl_ttc_detail WHERE idmau = " + idMau + " AND typeid = " + typePart;
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        //DataSet ds = db.GetDataSet(sql);
        if (dt != null && dt.Rows.Count > 0)
        {
            if (typePart == 1)
            {
                ltTongQuan.Text = dt.Rows[0]["thongtin"].ToString();
            }
            else if (typePart == 4)
            {
                ltHoatDongThanhPhan.Text = dt.Rows[0]["thongtin"].ToString();
            }
            else if (typePart == 8)
            {
                ltTaiLieuThamKhao.Text = dt.Rows[0]["thongtin"].ToString();
            }
            if (typePart == 2)
            {
                //rptHanhViChung.DataSource = dt;
                //rptHanhViChung.DataBind();
                
                gridHanhViChung.DataSource = dt;    
                gridHanhViChung.DataBind();
            }
            else if (typePart == 3)
            {
                //rptKeyDacBiet.DataSource = dt;
                //rptKeyDacBiet.DataBind();
                gridKeyDacBiet.DataSource = dt;
                gridKeyDacBiet.DataBind();
            }
            else if (typePart == 5)
            {
                gridThongTinCC.DataSource = dt;
                gridThongTinCC.DataBind();
            }
            else if (typePart == 6)
            {
                gridKyThuatMalware.DataSource = dt;
                gridKyThuatMalware.DataBind();
            }
            else if (typePart == 7)
            {
                gridHanhViMalware.DataSource = dt;
                gridHanhViMalware.DataBind();
            }
        }
    }

    protected void rptItemDataBond(object sender, RepeaterItemEventArgs e)
    {

    }

    protected void btnEditTongQuan_Click(object sender, EventArgs e)
    {
        hdnPart.Value = "1";
        hdnIDMau.Value = Session["idMau"].ToString();
        ckEditorTongQuan.Text = ltTongQuan.Text;
        btnEditTongQuan.Visible = false;
        //divPopupEdit.Attributes.Add("style", "display: block");
        divCKEditorTongQuan.Attributes.Add("style", "display: block");
    }

    protected void btnOKTongQuan_Click(object sender, EventArgs e)
    {
        db = new class_database();
        string[] _param = { "thongtin", "thongtindecode" };
        string thongTinDecode = Regex.Replace(Server.HtmlDecode(ckEditorTongQuan.Text), "<.*?>", string.Empty);
        string[] _value = { ckEditorTongQuan.Text, thongTinDecode };
        string _where = "typeid = " + hdnPart.Value + " AND idmau = " + hdnIDMau.Value;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        divCKEditorTongQuan.Attributes.Add("style", "display: none");
        string str = Server.HtmlDecode(ckEditorTongQuan.Text);
        Response.Redirect(Request.RawUrl, true);
    }

    protected void btnCancelTongQuan_Click(object sender, EventArgs e)
    {
        divCKEditorTongQuan.Attributes.Add("style", "display: none");
        btnEditTongQuan.Visible = true;
    }


    protected string GetIDFirstMau(string idLoaiMau)
    {
        string idFirst = "1";
        string sql = "SELECT id FROM tbl_mau WHERE type = " + idLoaiMau + " ORDER BY name LIMIT 1";
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        if (dt != null && dt.Rows.Count > 0)
        {
            idFirst = dt.Rows[0]["id"].ToString();
        }
        return idFirst;
    }

    // Click để hiển thị toàn bộ các nút edit cho các phần
    protected void btnEditThongTinChung_Click(object sender, EventArgs e)
    {
        btnEditTongQuan.Attributes.Add("style", "display: block");
        gridHanhViChung.Columns[3].Visible = true;
        divSubmitResetHanhViChung.Attributes.Add("style", "display: block");
        gridKeyDacBiet.Columns[3].Visible = true;
        divSubmitResetKeyDacBiet.Attributes.Add("style", "display: block");
        btnEditHoatDongThanhPhan.Attributes.Add("style", "display: block");
        gridThongTinCC.Columns[3].Visible = true;
        divSubmitResetThongTinCC.Attributes.Add("style", "display: block");
        gridKyThuatMalware.Columns[3].Visible = true;
        divSubmitResetKyThuatMalware.Attributes.Add("style", "display: block");
        gridHanhViMalware.Columns[3].Visible = true;
        divSubmitResetHanhViMalware.Attributes.Add("style", "display: block");
        btnEditTaiLieu.Attributes.Add("style", "display: block");
    }

    protected void btnDeleteThongTinChung_Click(object sender, EventArgs e)
    {
        if (hdnCheckConfirm.Value == "yes")
        {
            string idMau = Session["idMau"].ToString();
            db = new class_database();
            string _where = "idmau = " + idMau;
            db.DeleteRecord("tbl_ttc_detail", _where);
            string _where2 = "idloaibai = 1 AND idmau = " + idMau;
            db.DeleteRecord("tbl_baiphantich", _where2);
            Response.Redirect("Default.aspx?module=Template&view=General&idMau=" + idMau);
        }
    }


    //
    protected void btnSubmitHanhViChung_Click(object sender, EventArgs e)
    {
        if (tbNoiDung2.Text == "" && tbThongTin2.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = {"typeid", "noidung", "thongtin", "idmau"};
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = {"2", tbNoiDung2.Text, tbThongTin2.Text, idMau};
            string[] _type = {"int", "string", "string", "int"};
            db.InsertRecord("tbl_ttc_detail", _param, _value, _type);
            tbNoiDung2.Text = "";
            tbThongTin2.Text = "";
            LoadData(2, idMau);
        }
    }

    protected void btnResetHanhViChung_Click(object sender, EventArgs e)
    {
        tbNoiDung2.Text = "";
        tbThongTin2.Text = "";
    }


    protected void gridHanhViChung_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridHanhViChung.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(2, idMau);
    }

    protected void gridHanhViChung_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDHanhViChung = gridHanhViChung.Rows[e.RowIndex].FindControl("lbIDHanhViChung") as Label;
        TextBox tbNoiDungHanhViChung = gridHanhViChung.Rows[e.RowIndex].FindControl("tbNoiDungHanhViChung") as TextBox;
        TextBox tbThongTinHanhViChung = gridHanhViChung.Rows[e.RowIndex].FindControl("tbThongTinHanhViChung") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = {"noidung", "thongtin"};
        string[] _value = {tbNoiDungHanhViChung.Text.ToString(), tbThongTinHanhViChung.Text.ToString()};
        string _where = "id = " + lbIDHanhViChung.Text;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        gridHanhViChung.EditIndex = -1;
        LoadData(2, idMau);
    }

    protected void gridHanhViChung_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridHanhViChung.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(2, idMau);
    }

    protected void gridHanhViChung_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDHanhViChung = gridHanhViChung.Rows[e.RowIndex].FindControl("lbIDHanhViChung") as Label;
        db = new class_database();
        string _where = "id = " + lblIDHanhViChung.Text.ToString();
        db.DeleteRecord("tbl_ttc_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(2, idMau);
    }

    protected void gridHanhViChung_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void btnSubmitKeyDacBiet_Click(object sender, EventArgs e)
    {
        if (tbNoiDung3.Text == "" && tbThongTin3.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "3", tbNoiDung3.Text, tbThongTin3.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttc_detail", _param, _value, _type);
            tbNoiDung3.Text = "";
            tbThongTin3.Text = "";
            LoadData(3, idMau);
        }
    }

    protected void btnResetKeyDacBiet_Click(object sender, EventArgs e)
    {
        tbNoiDung3.Text = "";
        tbThongTin3.Text = "";
    }

    protected void gridKeyDacBiet_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridKeyDacBiet.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(3, idMau);
    }

    protected void gridKeyDacBiet_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridKeyDacBiet_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDKeyDacBiet = gridKeyDacBiet.Rows[e.RowIndex].FindControl("lbIDKeyDacBiet") as Label;
        db = new class_database();
        string _where = "id = " + lblIDKeyDacBiet.Text.ToString();
        db.DeleteRecord("tbl_ttc_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(3, idMau);
    }

    protected void gridKeyDacBiet_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridKeyDacBiet.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(3, idMau);
    }

    protected void gridKeyDacBiet_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDKeyDacBiet = gridKeyDacBiet.Rows[e.RowIndex].FindControl("lbIDKeyDacBiet") as Label;
        TextBox tbNoiDungKeyDacBiet = gridKeyDacBiet.Rows[e.RowIndex].FindControl("tbNoiDungKeyDacBiet") as TextBox;
        TextBox tbThongTinKeyDacBiet = gridKeyDacBiet.Rows[e.RowIndex].FindControl("tbThongTinKeyDacBiet") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungKeyDacBiet.Text.ToString(), tbThongTinKeyDacBiet.Text.ToString() };
        string _where = "id = " + lbIDKeyDacBiet.Text;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        gridKeyDacBiet.EditIndex = -1;
        LoadData(3, idMau);
    }

    protected void btnEditHoatDongThanhPhan_Click(object sender, EventArgs e)
    {
        hdnPart.Value = "4";
        hdnIDMau.Value = Session["idMau"].ToString();
        CKEditorHoatDongThanhPhan.Text = ltHoatDongThanhPhan.Text;
        divCKEditorHoatDongThanhPhan.Attributes.Add("style", "display: block");
        btnEditHoatDongThanhPhan.Visible = false;
    }

    protected void btnOKHoatDongThanhPhan_Click(object sender, EventArgs e)
    {
        string part = hdnPart.Value;
        string idMau = hdnIDMau.Value;
        string[] _param = { "thongtin", "thongtindecode" };
        string thongTinDecode = Regex.Replace(Server.HtmlDecode(CKEditorHoatDongThanhPhan.Text), "<.*?>", string.Empty);
        string[] _value = { CKEditorHoatDongThanhPhan.Text, thongTinDecode };
        string _where = "typeid = " + part + " AND idmau = " + idMau;
        db = new class_database();
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        divCKEditorHoatDongThanhPhan.Attributes.Add("style", "display: none");
        Response.Redirect(Request.RawUrl, true);
    }

    protected void btnCancelHoatDongThanhPhan_Click(object sender, EventArgs e)
    {
        divCKEditorHoatDongThanhPhan.Attributes.Add("style", "display: none");
        btnEditHoatDongThanhPhan.Visible = true;
    }

    protected void btnSubmitThongTinCC_Click(object sender, EventArgs e)
    {
        if (tbNoiDung5.Text == "" && tbThongTin5.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "5", tbNoiDung5.Text, tbThongTin5.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttc_detail", _param, _value, _type);
            tbNoiDung5.Text = "";
            tbThongTin5.Text = "";
            LoadData(5, idMau);
        }
    }

    protected void btnResetThongTinCC_Click(object sender, EventArgs e)
    {
        tbNoiDung5.Text = "";
        tbThongTin5.Text = "";
    }

    protected void gridThongTinCC_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridThongTinCC.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(5, idMau);
    }

    protected void gridThongTinCC_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridThongTinCC_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDThongTinCC = gridThongTinCC.Rows[e.RowIndex].FindControl("lbIDThongTinCC") as Label;
        db = new class_database();
        string _where = "id = " + lblIDThongTinCC.Text.ToString();
        db.DeleteRecord("tbl_ttc_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(5, idMau);
    }

    protected void gridThongTinCC_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridThongTinCC.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(5, idMau);
    }

    protected void gridThongTinCC_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDThongTinCC = gridThongTinCC.Rows[e.RowIndex].FindControl("lbIDThongTinCC") as Label;
        TextBox tbNoiDungThongTinCC = gridThongTinCC.Rows[e.RowIndex].FindControl("tbNoiDungThongTinCC") as TextBox;
        TextBox tbThongTinThongTinCC = gridThongTinCC.Rows[e.RowIndex].FindControl("tbThongTinThongTinCC") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungThongTinCC.Text.ToString(), tbThongTinThongTinCC.Text.ToString() };
        string _where = "id = " + lbIDThongTinCC.Text;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        gridThongTinCC.EditIndex = -1;
        LoadData(5, idMau);
    }









    protected void btnSubmitKyThuatMalware_Click(object sender, EventArgs e)
    {
        if (tbNoiDung6.Text == "" && tbThongTin6.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "6", tbNoiDung6.Text, tbThongTin6.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttc_detail", _param, _value, _type);
            tbNoiDung6.Text = "";
            tbThongTin6.Text = "";
            LoadData(6, idMau);
        }
    }

    protected void btnResetKyThuatMalware_Click(object sender, EventArgs e)
    {
        tbNoiDung6.Text = "";
        tbThongTin6.Text = "";
    }

    protected void gridKyThuatMalware_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridKyThuatMalware.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(6, idMau);
    }

    protected void gridKyThuatMalware_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridKyThuatMalware_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDKyThuatMalware = gridKyThuatMalware.Rows[e.RowIndex].FindControl("lbIDKyThuatMalware") as Label;
        db = new class_database();
        string _where = "id = " + lblIDKyThuatMalware.Text.ToString();
        db.DeleteRecord("tbl_ttc_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(6, idMau);
    }

    protected void gridKyThuatMalware_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridKyThuatMalware.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(6, idMau);
    }

    protected void gridKyThuatMalware_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDKyThuatMalware = gridKyThuatMalware.Rows[e.RowIndex].FindControl("lbIDKyThuatMalware") as Label;
        TextBox tbNoiDungKyThuatMalware = gridKyThuatMalware.Rows[e.RowIndex].FindControl("tbNoiDungKyThuatMalware") as TextBox;
        TextBox tbThongTinKyThuatMalware = gridKyThuatMalware.Rows[e.RowIndex].FindControl("tbThongTinKyThuatMalware") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungKyThuatMalware.Text.ToString(), tbThongTinKyThuatMalware.Text.ToString() };
        string _where = "id = " + lbIDKyThuatMalware.Text;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        gridKyThuatMalware.EditIndex = -1;
        LoadData(6, idMau);
    }














    protected void btnSubmitHanhViMalware_Click(object sender, EventArgs e)
    {
        if (tbNoiDung7.Text == "" && tbThongTin7.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "7", tbNoiDung7.Text, tbThongTin7.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttc_detail", _param, _value, _type);
            tbNoiDung7.Text = "";
            tbThongTin7.Text = "";
            LoadData(7, idMau);
        }
    }

    protected void btnResetHanhViMalware_Click(object sender, EventArgs e)
    {
        tbNoiDung7.Text = "";
        tbThongTin7.Text = "";
    }

    protected void gridHanhViMalware_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridHanhViMalware.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(7, idMau);
    }

    protected void gridHanhViMalware_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridHanhViMalware_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDHanhViMalware = gridHanhViMalware.Rows[e.RowIndex].FindControl("lbIDHanhViMalware") as Label;
        db = new class_database();
        string _where = "id = " + lblIDHanhViMalware.Text.ToString();
        db.DeleteRecord("tbl_ttc_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(7, idMau);
    }

    protected void gridHanhViMalware_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridHanhViMalware.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(7, idMau);
    }

    protected void gridHanhViMalware_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDHanhViMalware = gridHanhViMalware.Rows[e.RowIndex].FindControl("lbIDHanhViMalware") as Label;
        TextBox tbNoiDungHanhViMalware = gridHanhViMalware.Rows[e.RowIndex].FindControl("tbNoiDungHanhViMalware") as TextBox;
        TextBox tbThongTinHanhViMalware = gridHanhViMalware.Rows[e.RowIndex].FindControl("tbThongTinHanhViMalware") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungHanhViMalware.Text.ToString(), tbThongTinHanhViMalware.Text.ToString() };
        string _where = "id = " + lbIDHanhViMalware.Text;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        gridHanhViMalware.EditIndex = -1;
        LoadData(7, idMau);
    }






    protected void btnEditTaiLieu_Click(object sender, EventArgs e)
    {
        hdnPart.Value = "8";
        hdnIDMau.Value = Session["idMau"].ToString();
        CKEditorThamKhao.Text = ltTaiLieuThamKhao.Text;
        btnEditTaiLieu.Visible = false;
        divThamKhao.Attributes.Add("style", "display: block");
    }

    protected void btnOKThamKhao_Click(object sender, EventArgs e)
    {
        string part = hdnPart.Value;
        string idMau = hdnIDMau.Value;
        db = new class_database();
        string[] _param = { "thongtin", "thongtindecode" };
        string thongTinDecode = Regex.Replace(Server.HtmlDecode(CKEditorThamKhao.Text), "<.*?>", string.Empty);
        string[] _value = { CKEditorThamKhao.Text, thongTinDecode };
        string _where = "typeid = " + part + " AND idmau = " + idMau;
        db.UpdateRecord("tbl_ttc_detail", _param, _value, _where);
        divThamKhao.Attributes.Add("style", "display: none");
        Response.Redirect(Request.RawUrl, true);
    }

    protected void btnCancelThamKhao_Click(object sender, EventArgs e)
    {
        divThamKhao.Attributes.Add("style", "display: none");
        btnEditTaiLieu.Visible = true;
    }

}